package com.example.demo.admin.test.guava;/**
 * Created by kete on 2018-09-27.
 */

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 作者：kete
 * 创建时间：2018-09-27 17:27
 * 功能描述：
 * 版本：
 */
public class ConfigBean {

    private EventBus bus;

    public EventBus getBus() {
        return bus;
    }

    public void setBus(EventBus bus) {
        this.bus = bus;
    }

    public ConfigBean() {

        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(20);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 20,
                30, TimeUnit.SECONDS, workQueue);
        bus = new AsyncEventBus(executor);
    }

    public static void main(String[] args) {
        ConfigBean configBean = new ConfigBean();
        EventListener listener = new EventListener();

        configBean.getBus().register(listener);


        new Thread(()->{
            LoginEvent  event = new LoginEvent("xiaoqiang","123456");
            configBean.getBus().post(event);
        }).start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
